6package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class BorrowContainer here.
 * 
 * @author Rasmus Andersen Borup 
 * @version 
 */
public class BorrowContainer
{
    // instance variables
    private ArrayList<Borrow> borrows;
    private static BorrowContainer instance;
    
    /**
     * Constructor for objects of class BorrowContainer
     */
    private BorrowContainer()
    {
        // initialising instance variables
        borrows = new ArrayList<Borrow>();
    }

    public static BorrowContainer getInstance()
    {
        instance = new BorrowContainer();
        return instance;
    }
    
    public Borrow getBorrow(int dvdId)
    {
        boolean found = false;
        int i = 0;
        Borrow wantedBorrow = null;
        while(!found && i < borrows.size())
        {
            if(borrows.get(i).getDvdId() == dvdId)
            {
                wantedBorrow = borrows.get(i);
                found = true;
            }
            else
            {
                i++;
            }
        }
        return wantedBorrow;
    }
    
    public ArrayList<Borrow> getBorrows()
    {
        return borrows;
    }

    public void addBorrow(Borrow borrow)
    {
        borrows.add(borrow);
    }
    
    public void removeBorrow(int dvdId)
    {
        borrows.remove(getBorrow(dvdId));
    }
    
    public void printInfo(int dvdId)
    {
        getBorrow(dvdId).printInfo();
    }
    
    public void printBorrows()
    {
        for(Borrow borrow : borrows)
        {
            borrow.printInfo();
            System.out.println();
        }
    }
    
}
